package com.neusoft.resourceserver.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.neusoft.resourceserver.entity.Resource;
import com.neusoft.resourceserver.service.IResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liuxp
 * @since 2021-07-13
 */
@RestController
public class ResourceController {

    @Autowired
    IResourceService iResourceService;

    @GetMapping("/getRoles")
    public String getRoles(String url) {
        System.out.println("Method getRoles called");
        if(url.charAt(url.length() - 1)>='0'&& url.charAt(url.length() - 1)<='9'){
            int end = url.lastIndexOf('/');
            url = url.substring(0, end);
        }
        Resource resource = iResourceService.getOne(Wrappers.<Resource>lambdaQuery().eq(Resource::getUrl, url));

        if (resource==null)
            return null;
        return resource.getRoles();
    }
}

